from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-03 14:10:02.648292
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 03, Apr, 2021
Time: 14:10:06
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.3205
Nobs: 250.000 HQIC: -48.0780
Log likelihood: 2970.91 FPE: 7.91725e-22
AIC: -48.5882 Det(Omega_mle): 5.56255e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445576 0.127173 3.504 0.000
L1.Burgenland 0.073801 0.062885 1.174 0.241
L1.Kärnten -0.218875 0.054298 -4.031 0.000
L1.Niederösterreich 0.078566 0.139852 0.562 0.574
L1.Oberösterreich 0.225295 0.129611 1.738 0.082
L1.Salzburg 0.265787 0.070471 3.772 0.000
L1.Steiermark 0.137968 0.090886 1.518 0.129
L1.Tirol 0.115814 0.061803 1.874 0.061
L1.Vorarlberg -0.030599 0.057140 -0.535 0.592
L1.Wien -0.080492 0.117317 -0.686 0.493
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.483808 0.151606 3.191 0.001
L1.Burgenland 0.005200 0.074967 0.069 0.945
L1.Kärnten 0.336350 0.064729 5.196 0.000
L1.Niederösterreich 0.106755 0.166720 0.640 0.522
L1.Oberösterreich -0.075458 0.154512 -0.488 0.625
L1.Salzburg 0.211875 0.084011 2.522 0.012
L1.Steiermark 0.114904 0.108347 1.061 0.289
L1.Tirol 0.137533 0.073676 1.867 0.062
L1.Vorarlberg 0.156897 0.068118 2.303 0.021
L1.Wien -0.464998 0.139856 -3.325 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300504 0.061817 4.861 0.000
L1.Burgenland 0.096488 0.030567 3.157 0.002
L1.Kärnten -0.015750 0.026393 -0.597 0.551
L1.Niederösterreich 0.048022 0.067980 0.706 0.480
L1.Oberösterreich 0.287239 0.063001 4.559 0.000
L1.Salzburg 0.016898 0.034255 0.493 0.622
L1.Steiermark 0.018565 0.044178 0.420 0.674
L1.Tirol 0.067210 0.030041 2.237 0.025
L1.Vorarlberg 0.084454 0.027775 3.041 0.002
L1.Wien 0.102063 0.057026 1.790 0.073
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214710 0.063386 3.387 0.001
L1.Burgenland 0.021174 0.031344 0.676 0.499
L1.Kärnten 0.007852 0.027063 0.290 0.772
L1.Niederösterreich 0.046661 0.069706 0.669 0.503
L1.Oberösterreich 0.402444 0.064601 6.230 0.000
L1.Salzburg 0.082704 0.035125 2.355 0.019
L1.Steiermark 0.135004 0.045300 2.980 0.003
L1.Tirol 0.049031 0.030804 1.592 0.111
L1.Vorarlberg 0.082666 0.028480 2.903 0.004
L1.Wien -0.042217 0.058474 -0.722 0.470
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.511663 0.124003 4.126 0.000
L1.Burgenland 0.083356 0.061318 1.359 0.174
L1.Kärnten 0.011299 0.052944 0.213 0.831
L1.Niederösterreich -0.027389 0.136365 -0.201 0.841
L1.Oberösterreich 0.131424 0.126380 1.040 0.298
L1.Salzburg 0.057060 0.068715 0.830 0.406
L1.Steiermark 0.093433 0.088620 1.054 0.292
L1.Tirol 0.210779 0.060262 3.498 0.000
L1.Vorarlberg 0.029860 0.055716 0.536 0.592
L1.Wien -0.092700 0.114392 -0.810 0.418
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189973 0.096981 1.959 0.050
L1.Burgenland -0.017455 0.047956 -0.364 0.716
L1.Kärnten -0.013582 0.041407 -0.328 0.743
L1.Niederösterreich -0.019041 0.106650 -0.179 0.858
L1.Oberösterreich 0.403719 0.098840 4.085 0.000
L1.Salzburg 0.013031 0.053741 0.242 0.808
L1.Steiermark -0.001440 0.069309 -0.021 0.983
L1.Tirol 0.154731 0.047130 3.283 0.001
L1.Vorarlberg 0.058704 0.043575 1.347 0.178
L1.Wien 0.236836 0.089465 2.647 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.247218 0.119597 2.067 0.039
L1.Burgenland 0.020038 0.059139 0.339 0.735
L1.Kärnten -0.064752 0.051063 -1.268 0.205
L1.Niederösterreich -0.063443 0.131520 -0.482 0.630
L1.Oberösterreich 0.018104 0.121889 0.149 0.882
L1.Salzburg 0.075891 0.066273 1.145 0.252
L1.Steiermark 0.336956 0.085472 3.942 0.000
L1.Tirol 0.457797 0.058121 7.877 0.000
L1.Vorarlberg 0.149252 0.053736 2.777 0.005
L1.Wien -0.171987 0.110328 -1.559 0.119
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.140210 0.141042 0.994 0.320
L1.Burgenland 0.050621 0.069743 0.726 0.468
L1.Kärnten -0.070591 0.060219 -1.172 0.241
L1.Niederösterreich 0.194845 0.155103 1.256 0.209
L1.Oberösterreich -0.004334 0.143745 -0.030 0.976
L1.Salzburg 0.202449 0.078157 2.590 0.010
L1.Steiermark 0.115567 0.100797 1.147 0.252
L1.Tirol 0.056510 0.068542 0.824 0.410
L1.Vorarlberg 0.100387 0.063372 1.584 0.113
L1.Wien 0.218429 0.130111 1.679 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.590736 0.076708 7.701 0.000
L1.Burgenland -0.041327 0.037931 -1.090 0.276
L1.Kärnten -0.024910 0.032751 -0.761 0.447
L1.Niederösterreich 0.014330 0.084356 0.170 0.865
L1.Oberösterreich 0.326006 0.078178 4.170 0.000
L1.Salzburg 0.019694 0.042507 0.463 0.643
L1.Steiermark -0.030740 0.054821 -0.561 0.575
L1.Tirol 0.086761 0.037278 2.327 0.020
L1.Vorarlberg 0.111097 0.034466 3.223 0.001
L1.Wien -0.043208 0.070763 -0.611 0.541
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.138637 0.036985 0.163384 0.216639 0.053880 0.079388 -0.004959 0.150848
Kärnten 0.138637 1.000000 0.019832 0.204209 0.178685 -0.066846 0.160009 0.022638 0.307341
Niederösterreich 0.036985 0.019832 1.000000 0.247768 0.069807 0.297257 0.138717 0.029574 0.306163
Oberösterreich 0.163384 0.204209 0.247768 1.000000 0.299409 0.273348 0.089534 0.059898 0.135754
Salzburg 0.216639 0.178685 0.069807 0.299409 1.000000 0.158843 0.047844 0.089323 -0.000237
Steiermark 0.053880 -0.066846 0.297257 0.273348 0.158843 1.000000 0.105649 0.093049 -0.119336
Tirol 0.079388 0.160009 0.138717 0.089534 0.047844 0.105649 1.000000 0.163145 0.143213
Vorarlberg -0.004959 0.022638 0.029574 0.059898 0.089323 0.093049 0.163145 1.000000 0.001284
Wien 0.150848 0.307341 0.306163 0.135754 -0.000237 -0.119336 0.143213 0.001284 1.000000